home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / appkit.cpp < prev    next >
C/C++ Source or Header  |  1994-10-10  |  7KB  |  252 lines

  1. #include "appkit.h"
  2. #include "dim.h"
  3.  
  4. ApplicationKit::ApplicationKit(int stp, loc minsz)
  5.     : WindowManager(stp)
  6.     {
  7.     applExit = 0;
  8.     minsize = minsz;
  9.     }
  10. //////////////////////////////
  11. int ApplicationKit::moveTo(int number)
  12.     {
  13.     Kit::moveTo(number);
  14.     WindowManager::moveTo(list[current]);
  15.     return current;
  16.     }
  17. ///////////////////////////
  18. int ApplicationKit::shift()
  19.     {
  20.     ApplicationKit::moveTo(Kit::get(stack[0]));
  21.     return current;
  22.     }
  23. ///////////////////////////
  24. void ApplicationKit::add(Visible* object)
  25.     {
  26.     Kit::add(object);
  27.     object->set_object_number(object_number + used * step);
  28.     }
  29. ///////////////////////////
  30. void ApplicationKit::background(Visible* object)
  31.     {
  32.     Kit::background(object);
  33.     object->set_object_number(object_number);
  34.     }
  35. ///////////////////////////
  36. Visible* ApplicationKit::remove(int number)
  37.     {
  38.     Visible* vis = Kit::remove(number);
  39.     return vis;
  40.     }
  41. ////////////////////
  42. void ApplicationKit::insert(Visible* , int)
  43.     {
  44.     }
  45. ////////////////////////
  46. void ApplicationKit::exe(int)
  47.     {
  48.     if(used == 0)
  49.         return;
  50.  
  51.     mouseShowCursor();
  52.     moveTo(1);
  53.  
  54.     while(1)
  55.     {
  56.     if(!(list[current]->active()))
  57.         WindowManager::show_window(list[current]);
  58.     list[current]->exe();
  59.  
  60.     if(global_i[0])
  61.         {
  62.         if(global_i[0] > 100)
  63.         {
  64.         int w;
  65.         if(!(w = application(global_i[0] + global_num - 1)))
  66.             continue;     // it is application function only
  67.         if(w == 1)        // it is too, but after execution hide
  68.             {             // this object and pass control to previous
  69.             WindowManager::hide_window();
  70.             moveTo(list[current]->isCall());
  71.             continue;
  72.             }
  73.         // else --> it is not only application, we expect next menu
  74.         }
  75.             if(global_i[0] == AC_REDRAW)
  76.         {
  77.                 rect work = list[current]->bound();
  78.                 if(global_i[1] == AC_MOVE)
  79.                     work = get_dim(FIG_RECTANGLE,
  80.                 MOVE, list[0]->bound(), work,
  81.                 loc(work.width(), work.height()));
  82.                 else
  83.                     work = get_dim(FIG_RECTANGLE,
  84.                 RESIZE, list[0]->bound(), work,
  85.                 screenLocLT(minsize));
  86.  
  87.                 WindowManager::redraw_window(work);
  88.                 continue;
  89.         }
  90.             if(global_i[0] == AC_RESIZE || global_i[0] == AC_MOVE)
  91.                 return;
  92.         }
  93.  
  94.     if(e.what == KEYEVENT || e.what == SHIFTKEYEVENT)
  95.         {
  96.         switch(e.key)
  97.         {
  98.         case EVENT_ALT_F4:
  99.             return;
  100.         case EVENT_ALT_F3:
  101.                     if(global_i[0] == AC_ERASE && current > 1
  102.                 && list[current]->isRet(RET_REMOVE))
  103.             {
  104.                         WindowManager::hide_window();
  105.                         delete remove(current);
  106.                         WindowManager::show_window(list[1]);
  107.             moveTo(1);
  108.             continue;
  109.             }
  110.                     if(!isRet(RET_REMOVE))   // Ignore this command
  111.             continue;
  112.             return;
  113.                 case EVENT_ALT_TAB:
  114.                     return;
  115.         case EVENT_ESC:
  116.                     if(list[current]->isRet(RET_CANCEL)
  117.                 && current != 1) // to hide
  118.                         WindowManager::hide_window();
  119.             int r;
  120.             if((r = current) > 1)  // it is possible go to previous object
  121.             {
  122.             int call;
  123.             if((call = list[current]->isCall()) == 0)
  124.                 call = 1;
  125.                         WindowManager::show_window(ApplicationKit::get(call));
  126.                         moveTo(call);
  127.             }
  128.             if(r == 1)        // !!!
  129.             {
  130.             if(list[1]->isRet(RET_CANCEL)
  131.                && (applExit == 0 || application(applExit)))
  132.                 {
  133.                             e.key = EVENT_ALT_F4;  // remove from upper container
  134.                 return;
  135.                 }
  136.             continue;     // it was mistake - we want not to exit
  137.             }
  138.             break;
  139.         case EVENT_F10:
  140.                     F10_shift();
  141.             break;
  142.         case EVENT_F6:                     // go to the next object
  143.             F6_shift();
  144.             break;
  145.         case EVENT_F2:
  146.         case EVENT_RETURN:
  147.             if(list[current]->isRet(RET_OK))
  148.             WindowManager::hide_window();
  149.             if(list[current]->isPoint())
  150.             {
  151.             int wh = (list[current]->isRet(RET_TRANSFER))
  152.                 ? list[current]->isPoint()
  153.                 : list[current]->isPoint() + global_num - 1;
  154.             if(wh <= used)
  155.                 {
  156.                 get(wh)->set_call(current);
  157.                 WindowManager::show_window(list[wh]);
  158.                 moveTo(wh);
  159.                 }
  160.             else
  161.                 {
  162.                 get(used)->set_call(current);
  163.                             WindowManager::show_window(list[used]);
  164.                 moveTo(used);
  165.                 }
  166.             }
  167.             else
  168.             {
  169.                         WindowManager::show_window(
  170.                 list[list[current]->isCall()]);
  171.             moveTo(list[current]->isCall());
  172.             }
  173.  
  174.         default: break;
  175.         }
  176.         }
  177.     else
  178.         if(e.mouse1())
  179.         {
  180.         if(!mouse_shift(e.where()))
  181.                     return;
  182.         }
  183.     }
  184.     }
  185. ////////////////////
  186. int ApplicationKit::mouse_shift(loc pos)
  187.     {
  188.     if(stack[s_used]->mouse_in(pos))      // Mouse pressed in the same window.
  189.         return 1;                         // Return SUCCESS.
  190.     mouseHideCursor();
  191.  
  192.     for(int i = s_used; i >= 1; i--)                  // For visible objects.
  193.     {
  194.         if(!stack[i]->mouse_in(pos))                  // Not in this window.
  195.             {
  196.         if(stack[i]->isRet(RET_MOUSE))            // Hide window if
  197.                 {                                     // necessary.
  198.                 WindowManager::moveTo(stack[i]);
  199.         WindowManager::hide_window();
  200.                 }
  201.             }
  202.     else                                          // Pressed in this
  203.         {                                         // window.
  204.             WindowManager::show_window(stack[i]);     // Flow up this window.
  205.         ApplicationKit::moveTo(get(stack[s_used])); // Assign input focus.
  206.         mouseShowCursor();
  207.             return 1;                                 // Return SUCCESS.
  208.         }
  209.     }
  210.     if(stack[0]->mouse_in(pos))                       // If 0-th, call 1-th.
  211.         {
  212.         ApplicationKit::moveTo(get(stack[s_used]));
  213.         WindowManager::show_window(stack[s_used]);
  214.         }
  215.     else                                              // Outside of base
  216.         {                                             // window.
  217.     mouseShowCursor();
  218.         return 0;                                     // Return FAIL.
  219.         }
  220.  
  221.     mouseShowCursor();
  222.     return 1;
  223.     }
  224. /////////////////////////
  225. void ApplicationKit::F10_shift()
  226.     {
  227.     mouseHideCursor();
  228.     for(int i = s_used; i > 1; i--)
  229.     {
  230.     if(stack[i]->isRet(RET_MOUSE))
  231.         {
  232.         WindowManager::moveTo(stack[i]);
  233.         WindowManager::hide_window();
  234.             }
  235.     }
  236.  
  237.     WindowManager::show_window(list[1]);
  238.     moveTo(1);
  239.     mouseShowCursor();
  240.     }
  241. /////////////////////
  242. void ApplicationKit::F6_shift()
  243.     {
  244.     mouseHideCursor();
  245.     while(s_used != 1 && stack[s_used]->isRet(RET_MOUSE))
  246.         WindowManager::hide_window();
  247.     WindowManager::show_window(stack[1]);
  248.     moveTo(get(stack[s_used]));
  249.     mouseShowCursor();
  250.     }
  251. /////////////////////
  252.